package com.gmail.blackdog1987.carcare.network.request.builder;

import android.content.Context;

import com.gmail.blackdog1987.carcare.Constant;
import com.gmail.blackdog1987.carcare.db.dao.UserDao;
import com.gmail.blackdog1987.carcare.network.request.RequestBuilder;
import com.gmail.blackdog1987.carcare.util.DeviceUtils;
import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class OrderRoadHelpRequestBuilder extends RequestBuilder {

	private static final String TAG = OrderRoadHelpRequestBuilder.class.getSimpleName();
	private String userid;
	private String name;
	private String phone;
	private String info;
	private String type;
	private String location;
	private String lat;
	private String lon;
	
	@Override
	public RequestParams buildRquest() {
		RequestParams params = new RequestParams();
		params.put("userid", String.valueOf(new UserDao().getUser().id));
		params.put("name", name);
		params.put("phone", phone);
		params.put("info", info);
		params.put("type", type);
		params.put("location", location);
		params.put("lat", lat);
		params.put("lon", lon);
		return params;
	}
	public OrderRoadHelpRequestBuilder setUserid(String userid){
		this.userid = userid;
		return this;
	}
	public OrderRoadHelpRequestBuilder setName(String name){
		this.name = name;
		return this;
	}
	public OrderRoadHelpRequestBuilder setPhone(String phone){
		this.phone = phone;
		return this;
	}
	public OrderRoadHelpRequestBuilder setInfo(String info){
		this.info = info;
		return this;
	}
	public OrderRoadHelpRequestBuilder setType(String type){
		this.type = type;
		return this;
	}
	
	public OrderRoadHelpRequestBuilder setLocation(String location){
		this.location = location;
		return this;
	}
	public OrderRoadHelpRequestBuilder setLat(String lat){
		this.lat = lat;
		return this;
	}
	public OrderRoadHelpRequestBuilder setLon(String lon){
		this.lon = lon;
		return this;
	}

	@Override
	public void postJsonRequest(Context context, AsyncHttpResponseHandler handler) {

		RequestParams params = buildRquest();
		
		AsyncHttpClient client = new AsyncHttpClient();
		client.setTimeout(Constant.TIMEOUT);
		client.setUserAgent(DeviceUtils.OS.getName());
		
		client.post(Constant.Action.ORDER_ROADHELP, params, handler);
		LogUtil.d(TAG, "post : " + params);
	}

}
